{% from pinInitializerImport import makePinInitializer as makePinInitializer %}
/**
 * \file
 * \brief Definitions of low-level UART drivers for USARTv2 in {{ board }} ({{ dictionary['chip']['compatible'][0] }} chip)
 *
 * \author Copyright (C) 2016-2020 Kamil Szczygiel https://distortec.com https://freddiechopin.info
 *
 * \par License
 * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not
 * distributed with this file, You can obtain one at https://mozilla.org/MPL/2.0/.
 *
 * \warning
 * Automatically generated file - do not edit!
 */

#include "distortos/chip/uarts.hpp"

#include "distortos/chip/ChipUartLowLevel.hpp"
#include "distortos/chip/PinInitializer.hpp"

#include "distortos/BIND_LOW_LEVEL_INITIALIZER.h"

namespace distortos
{

namespace chip
{
{% for key, uart in dictionary['UARTs'].items() if uart is mapping and 'ST,STM32-USART-v2' in uart['compatible'] %}

#ifdef DISTORTOS_CHIP_{{ key | upper }}_ENABLE

/*---------------------------------------------------------------------------------------------------------------------+
| {{ key | upper }}
+---------------------------------------------------------------------------------------------------------------------*/
{% for pinKey in ['CTS', 'RTS', 'RX', 'TX'] if pinKey in uart %}
{% if loop.first == True %}

namespace
{

/// pin initializers for {{ key | upper }}
const PinInitializer {{ key | lower }}PinInitializers[]
{
{% endif %}
		// {{ key | upper }} {{ pinKey }}
		{{ makePinInitializer(uart[pinKey]) | indent(8) | replace('    ', '\t') }}
{% if loop.last == True %}
};

/**
 * \brief Low-level chip initializer for {{ key | upper }}
 *
 * This function is called before constructors for global and static objects via BIND_LOW_LEVEL_INITIALIZER().
 */

void {{ key | lower }}LowLevelInitializer()
{
	for (auto& pinInitializer : {{ key | lower }}PinInitializers)
		pinInitializer();
}

BIND_LOW_LEVEL_INITIALIZER(50, {{ key | lower }}LowLevelInitializer);

}	// namespace
{% endif %}
{% endfor %}

ChipUartLowLevel {{ key | lower }} {ChipUartLowLevel::{{ key | lower }}Parameters};

/**
 * \brief {{ uart['interrupt']['vector'] }} interrupt handler
 */

extern "C" void {{ uart['interrupt']['vector'] }}_IRQHandler()
{
	{{ key | lower }}.interruptHandler();
}

#endif	// def DISTORTOS_CHIP_{{ key | upper }}_ENABLE
{% endfor %}

}	// namespace chip

}	// namespace distortos
